package com.pet.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.pet.system.controller.vo.AchievementsVo;
import com.pet.system.entity.Achievements;
import com.pet.system.mapper.AchievementsMapper;
import com.pet.system.service.AchievementsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class AchievementsServiceImpl implements AchievementsService {
    @Autowired
    private AchievementsMapper achievementsMapper;

    @Override
    public Achievements getInfo(Long id) {
        return achievementsMapper.selectById(id);
    }

    @Override
    public PageInfo<Achievements> getPageList(AchievementsVo achievements) {
        LambdaQueryWrapper<Achievements> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper
                .eq(StringUtil.isNotEmpty(achievements.getUsername()),Achievements::getUsername,achievements.getUsername())
        ;

        return PageHelper.startPage(achievements.getPageNo(), achievements.getPageSize())
                .doSelectPageInfo(() -> achievementsMapper.selectList(queryWrapper));
    }

    @Override
    public int remove(Long[] achievementsIds) {
        for (Long id : achievementsIds) {
            int i = achievementsMapper.deleteById(id);
        }
        return 1;
    }

    @Override
    public int edit(Achievements achievements) {
        return achievementsMapper.updateById(achievements);
    }

    @Override
    public int add(Achievements achievements) {
        return achievementsMapper.insert(achievements);
    }
}
